# Maintainer: Miloš Komarčević <miloskomarcevic@aim.com>

_realname=libinih
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=56
pkgrel=2
pkgdesc="A simple .INI file parser written in C (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url='https://github.com/benhoyt/inih'
license=('spdx:BSD-3-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-python")
source=("https://github.com/benhoyt/inih/archive/refs/tags/r${pkgver}.tar.gz")
sha256sums=('4f2ba6bd122d30281a8c7a4d5723b7af90b56aa828c0e88256d7fceda03a491a')

build() {
  mkdir -p build-${MSYSTEM}-static && cd build-${MSYSTEM}-static

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    meson setup \
      --prefix="${MINGW_PREFIX}" \
      --wrap-mode=nodownload \
      --auto-features=enabled \
      --buildtype=plain \
      -Ddefault_library=static \
      -Ddistro_install=true \
      -Dwith_INIReader=true \
      ../inih-r${pkgver}

  meson compile

  cd "${srcdir}"
  mkdir -p build-${MSYSTEM}-shared && cd build-${MSYSTEM}-shared

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    meson setup \
      --prefix="${MINGW_PREFIX}" \
      --wrap-mode=nodownload \
      --auto-features=enabled \
      --buildtype=plain \
      -Ddefault_library=shared \
      -Ddistro_install=true \
      -Dwith_INIReader=true \
      ../inih-r${pkgver}

  meson compile
}

package() {
  cd "${srcdir}/build-${MSYSTEM}-static"

  DESTDIR="${pkgdir}" meson install

  cd "${srcdir}/build-${MSYSTEM}-shared"

  DESTDIR="${pkgdir}" meson install

  install -Dm644 "${srcdir}/inih-r${pkgver}/LICENSE.txt" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
